using System;

namespace Infrastructure.WebApi
{
    /// <summary>
    /// 获取执行结果的辅助类
    /// </summary>
    public static class ResultHelper
    {
        /// <summary>
        /// 根据信息代码获得执行结果
        /// </summary>
        /// <param name="code">信息代码</param>
        /// <returns>执行结果对象</returns>
        public static Result Get(int code)
        {
            Result result = new Result();
            result.Code = code;
            return result;
        }

        /// <summary>
        /// 根据信息代码获得执行结果
        /// </summary>
        /// <param name="code">信息代码</param>
        /// <param name="ex">发生的异常</param>
        /// <param name="appendText">信息内容的附加信息，将附加到信息内容的末尾</param>
        /// <returns>执行结果对象</returns>
        public static Result Get(int code, Exception ex, string appendText = "")
        {
            Result result = new Result();
            result.Code = code;
            result.Message = ex.Message + appendText;
            return result;
        }

        /// <summary>
        /// 根据信息代码获得执行结果
        /// </summary>
        /// <param name="code">信息代码</param>
        /// <param name="appendText">信息内容的附加信息，将附加到信息内容的末尾</param>
        /// <returns>执行结果对象</returns>
        public static Result Get(int code, string appendText)
        {
            Result result = new Result();
            result.Code = code;
            result.Message = appendText;
            return result;
        }
    }
}
